package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.ReportService;
import com.sky.vo.OrderReportVO;
import com.sky.vo.SalesTop10ReportVO;
import com.sky.vo.TurnoverReportVO;
import com.sky.vo.UserReportVO;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalTime;

/**
 * @description
 * @author: ZXX-挚爱
 * @time: 2023/6/16 0:02
 */

@RestController
@RequestMapping("/admin/report")
public class ReportController {


    @Autowired
    private ReportService reportService;


    /** @author ZXX-挚爱
    * @Description 营业额数据统计
    * @Dete 0:11 2023/6/16
    * @Param [begin, end]
    * @return com.sky.result.Result<com.sky.vo.TurnoverReportVO>
    **/

    @GetMapping("/turnoverStatistics")
    @ApiOperation("营业额数据统计")
    private Result<TurnoverReportVO> turnoverStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
            ){
           TurnoverReportVO turnoverReportVO= reportService.getTurnover(begin,end);
            return Result.success(turnoverReportVO);
    }
    /** @author ZXX-挚爱
    * @Description 用户统计
    * @Dete 0:49 2023/6/16
    * @Param [begin, end]
    * @return com.sky.result.Result<com.sky.vo.UserReportVO>
    **/

    @GetMapping("/userStatistics")
    @ApiOperation("用户统计")
    private Result<UserReportVO> userStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
            ){
            UserReportVO userReportVO= reportService.getUserStatistics(begin,end);
            return Result.success(userReportVO);
    }

    /** @author ZXX-挚爱
    * @Description 订单统计
    * @Dete 19:53 2023/6/16
    * @Param [begin, end]
    * @return com.sky.result.Result<com.sky.vo.OrderReportVO>
    **/

    @GetMapping("/ordersStatistics")
    @ApiOperation("订单统计")
    private Result<OrderReportVO> orderStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
            ){
            OrderReportVO orderReportVO= reportService.getOrderStatistics(begin,end);
            return Result.success(orderReportVO);
    }

    /** @author ZXX-挚爱
    * @Description 销量top10统计
    * @Dete 20:57 2023/6/16
    * @Param [begin, end]
    * @return com.sky.result.Result<com.sky.vo.SalesTop10ReportVO>
    **/

    @GetMapping("/top10")
    @ApiOperation("销量top10统计")
    private Result<SalesTop10ReportVO> CountTop10(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
            ){
        SalesTop10ReportVO salesTop10ReportVO= reportService.getOrderTop(begin,end);
            return Result.success(salesTop10ReportVO);
    }
    @GetMapping("/export")
    @ApiOperation("导出Excel报表接口")
    private void export(HttpServletResponse response) throws IOException {
        XSSFWorkbook  wb = reportService.exportData();
        wb.write(response.getOutputStream());

    }

}
